<template>
    <!-- 其他检验规则维护 -->
    <p-card :bordered="false">

        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <p-form layout="inline" @keyup.enter.native="searchQuery">
                <p-row :gutter="24">
                    <p-col :xl="6" :lg="7" :md="8" :sm="24">
                        <p-form-item label="规则类型">
                            <j-dict-select-tag placeholder="请选择规则类型" v-model="queryParam.ruletype" dictCode="mes_ruletype"/>
                        </p-form-item>
                    </p-col>
                    <p-col :xl="6" :lg="7" :md="8" :sm="24">
                        <p-form-item label="规则编码">
                            <p-input placeholder="请输入规则编码" v-model="queryParam.ruleno"/>
                        </p-form-item>
                    </p-col>
                    <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <p-button type="primary" @click="searchQuery" icon="search">查询</p-button>
              <p-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</p-button>
                <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <p-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
                </a> -->
            </span>
                    </p-col>

                </p-row>
            </p-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
            <p-button @click="openAddBtn" type="primary" icon="plus">新增</p-button>

            <template v-if="cgButtonList && cgButtonList.length>0" v-for="(item,index) in cgButtonList">
                <p-button
                        v-if=" item.optType=='js' && (item.groupTag == null || item.groupTag == '' )"
                        :key=" 'cgbtn'+index "
                        @click="cgButtonJsHandler(item.buttonCode)"
                        type="primary"
                        :icon="item.buttonIcon"
                >{{ item.buttonName }}</p-button>
                <p-button
                        v-else-if=" item.optType=='action' && (item.groupTag == null || item.groupTag == '' )"
                        :key=" 'cgbtn'+index "
                        @click="cgButtonActionHandler(item.buttonCode)"
                        type="primary"
                        :icon="item.buttonIcon"
                >{{ item.buttonName }}</p-button>
            </template>

            <!-- 高级查询区域 -->
            <j-super-query :fieldList="fieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>

            <p-dropdown  v-for="(item,index) in groupTag" :key="index">
                <p-button >
                    {{item.name}}
                    <p-icon type="down" />
                </p-button>
                <p-menu slot="overlay"  >
                    <template  v-for="(items,indexs) in item.data">
                        <p-menu-item v-if=" items.optType=='js' " :key="indexs" @click="cgButtonJsHandler(items.buttonCode)">
                            <p-icon :type="items.buttonIcon" />{{items.buttonName}}
                        </p-menu-item>
                        <p-menu-item v-else-if=" items.optType=='action' " :key="indexs" @click="cgButtonActionHandler(items.buttonCode)">
                            <p-icon :type="items.buttonIcon" />{{items.buttonName}}
                        </p-menu-item>
                    </template>
                </p-menu>
            </p-dropdown>

            <p-dropdown v-if="selectedRowKeys.length > 0">
                <p-menu slot="overlay">
                    <p-menu-item key="1" @click="batchDel">
                        <p-icon type="delete" />删除
                    </p-menu-item>
                </p-menu>
                <p-button style="margin-left: 8px">
                    批量操作
                    <p-icon type="down" />
                </p-button>
            </p-dropdown>

        </div>
        <!-- table区域-begin -->
        <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected">清空</a>

                <span style="float:right;">
              <a @click="handleExportXls('其他检验规则')"><p-icon type="download" />导出</a>
                 <p-divider type="vertical" />
              <p-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
                 <a><p-icon type="import" />导入</a>
              </p-upload>
              <p-divider type="vertical" />
              <a @click="loadData()"><p-icon type="sync" />刷新</a>
              <p-divider type="vertical" />
                <p-popover title="自定义列" trigger="click" placement="leftBottom"  :overlay-style="getWidth">
                <template slot="content">
                  <p-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                    <p-row>
                      <template v-for="(item,index) in defColumns">
                        <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                            <p-col :span="12"><p-checkbox :value="item.dataIndex">{{ item.title }}</p-checkbox></p-col>
                        </template>
                      </template>
                    </p-row>
                  </p-checkbox-group>
                </template>
                <a><p-icon type="setting" />自定义列</a>
              </p-popover>
            </span>
            </div>


            <p-table
                    ref="table"
                    size="middle"
                    bordered
                    rowKey="id"
                    :columns="columns"
                    :dataSource="dataSource"
                    :pagination="ipagination"
                    :loading="loading"
                    :rowSelection="{fixed:true,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                    :customRow="clickThenSelect"
                    :rowClassName="setRowClassName"
                    @change="handleTableChange">


                <template slot="rulename" slot-scope="text,record">
                    <div>{{ruleNameMap[text].title}}</div>
                </template>

                <template slot="ruletype" slot-scope="text,record">
                    <div>{{ruleTypeMap[text].title}}</div>
                </template>

                <template slot="ruleno" slot-scope="text,record">
                    <div>{{text}}</div>
                </template>

                <!-- 状态插槽 -->
                <template slot="status_dictText" slot-scope="text,record">
                    <div v-if="!text" >/</div>
                    <p-tag v-else-if="text=='生效'" color="green"><p-icon type="check-circle" />生效</p-tag>
                    <p-tag v-else-if="text=='失效'" color="red"><p-icon type="close-circle" />失效</p-tag>
<!--                    <div v-if="record.status==1" style="color: #00FF00;">{{text}}</div>
                    <div v-else  style="color: red;">{{text}}</div>-->
                </template>



                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="imgSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
                    <img v-else :src="getImgView(text)" height="25px" alt="图片不存在" style="max-width:80px;font-size: 12px;font-style: italic;"/>
                </template>
                <template slot="fileSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
                    <p-button
                            v-else
                            :ghost="true"
                            type="primary"
                            icon="download"
                            size="small"
                            @click="uploadFile(text)">
                        下载
                    </p-button>
                </template>

                <span slot="action" slot-scope="text, record">
              <a @click="openEditBtn(record)">编辑</a>

              <p-divider type="vertical" />
              <p-dropdown>
                <a class="ant-dropdown-link">更多 <p-icon type="down" /></a>
                <p-menu slot="overlay">
                  <p-menu-item>
                    <p-popconfirm title="确定删除吗?" @confirm="() => deleteBtn(record.id)">
                      <a>删除</a>
                    </p-popconfirm>
                  </p-menu-item>
                    <template v-if="cgButtonLinkList && cgButtonLinkList.length>0" v-for="(btnItem,btnIndex) in cgButtonLinkList">
                      <p-menu-item :key=" 'cgbtnLink'+btnIndex " v-if="showLinkButton(btnItem,record)">
                        <a href="javascript:void(0);" @click="cgButtonLinkHandler(record,btnItem.buttonCode,btnItem.optType)">
                          <p-icon v-if="btnItem.buttonIcon" :type="btnItem.buttonIcon" />
                          {{ btnItem.buttonName }}
                        </a>
                      </p-menu-item>
                    </template>
                </p-menu>
              </p-dropdown>
            </span>
            </p-table>
        </div>
        <!-- table区域-end -->

        <mesQcInspectRule-modal ref="modalForm" :EnhanceJS="EnhanceJS"  @ok="modalFormOk"></mesQcInspectRule-modal>


        <p-modal v-model="pModalVisible" :title="pTitle" :width="900" @ok="pModalOk">
            <p-form-model
                    ref="ruleForm"
                    :model="form"
                    :rules="rules"
                    :label-col="labelCol"
                    :wrapper-col="wrapperCol"
            >
                <p-form-model-item label="规则类型" prop="ruletype">
                    <p-select v-model="form.ruletype" placeholder="请选择规则类型" >
                        <p-select-option
                                v-for="(item,index) in ruleTypeList"
                                :key="index"
                                :value="item.value"
                        >{{item.title}}</p-select-option>
                    </p-select>
                </p-form-model-item>

                <p-form-model-item label="规则编号" prop="ruleno">
                    <p-input v-model="form.ruleno" readOnly>

                    </p-input>
                </p-form-model-item>

                <p-form-model-item label="规则名称" prop="rulename" >
                    <p-select v-model="form.rulename" placeholder="请选择规则名称" @change="rulenameSelectChange">
                        <p-select-option
                                v-for="(item,index) in ruleNameList"
                                :key="index"
                                :value="item.value"
                        >{{item.title}}</p-select-option>
                    </p-select>
                </p-form-model-item>

                <p-form-model-item label="规则单位" prop="ruleUnit" v-if="!showContentSelect" >
                    <p-select v-model="form.ruleUnit" placeholder="请选择规则单位"@change="ruleUnitSelectChange" >
                        <p-select-option
                                v-for="(item,index) in ruleUnitList"
                                :key="index"
                                :value="item.value"
                        >{{item.title}}</p-select-option>
                    </p-select>
                </p-form-model-item>

                <div  v-if="!showContentSelect">
                    <p-form-model-item label="规则内容" prop="rulecontent" v-if="contentNum">
                        <p-input v-model="form.rulecontent" type="number">

                        </p-input>
                    </p-form-model-item>
                    <p-form-model-item label="规则内容" prop="rulecontent" v-if="!contentNum">
                        <p-input v-model="form.rulecontent">

                        </p-input>
                    </p-form-model-item>

                </div>



                <p-form-model-item label="规则内容" prop="rulecontent" v-if="showContentSelect">
                    <p-select  mode="multiple"  v-model="form.rulecontent" placeholder="请选择规则内容" >
                        <p-select-option
                                v-for="(item,index) in processList"
                                :key="index"
                                :value="item.value"
                        >{{item.title}}</p-select-option>
                    </p-select>
                </p-form-model-item>


                <p-form-model-item label="状态" prop="status">
                    <p-radio-group v-model="form.status">
                        <p-radio :value="1">
                            生效
                        </p-radio>
                        <p-radio :value="2">
                            失效
                        </p-radio>
                    </p-radio-group>
                </p-form-model-item>

                <p-form-model-item label="备注" prop="remark">
                    <p-textarea type="textArea" v-model="form.remark" >

                    </p-textarea>
                </p-form-model-item>

            </p-form-model>
        </p-modal>

        <!-- 弹出窗 -->
        <Fx-compontens-modal @ok="modalFormOk"  ref="modalCompon" :getList="queryInfo" :title="title" :dictOptions="dictOptions"></Fx-compontens-modal>
    </p-card>
</template>

<script>

    import { JeecgListMixin } from '@/mixins/JeecgListMixin'
    import {api} from '@/api/manage'
    import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
    import { filterObj } from '@/utils/util';
    import MesQcInspectRuleModal from './modules/MesQcInspectRuleModal'

    import Vue from 'vue'
    import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
    import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'
    import ButtonExpHandler from '@/components/jeecgbiz/modules/ButtonExpHandler'
    import { postAction,getAction,deleteAction,putAction } from '@/api/manage'
    import FxCompontensModal from "@/components/jeecgbiz/FxCompontensModal"



    //高级查询modal需要参数
    const superQueryFieldList=[
        {
            value:'ruleno',
            text: '规则编码',
            type: 'String'
        },
        {
            value:'rulename',
            text: '规则名称',
            type: 'String',
            dictCode: 'mes_otherrule_rulename'

        },

        {
            value:'ruletype',
            text: '规则类型',
            type: 'select',
            dictCode: 'mes_ruletype'
        },
        {
            value:'ruleUnit',
            text: '单位',
            type: 'String',
            dictCode: 'mes_otherrule_ruleunit'
        },
        {
            value:'createBy',
            text: '创建人',
            type: 'string'
        },
        {
            value:'createTime',
            text: '创建日期',
            type: 'Date'
        },
        {
            value:'updateBy',
            text: '更新人',
            type: 'string'
        },
        {
            value:'updateTime',
            text: '更新日期',
            type: 'Date'
        },
        {
            value:'status',
            text: '状态',
            type: 'select',
            dictCode: 'mes_status'
        },
        {
            value:'remark',
            text: '备注',
            type: 'string'
        },
    ]

    export default {
        name: "MesQcInspectRuleList",
        mixins:[JeecgListMixin],
        components: {
            JSuperQuery,
            JDictSelectTag,
            FxCompontensModal,
            MesQcInspectRuleModal
        },
        data () {
            return {
                fieldList:superQueryFieldList,
                superQueryFlag:false,
                superQueryParams: '',
                description: '其他检验规则管理页面',
                cgButtonLinkList:[],

                showContentSelect:false,
                contentNum:false,

                ruleNo:'',
                editP:{},

                pModalVisible:false,
                pTitle:'',
                labelCol: { span: 4 },
                wrapperCol: { span: 14 },
                form: {
                    ruletype:'',
                    ruleno:'',
                    rulename:'',
                    rulecontent:'',
                    status:'',
                    remark:'',
                    ruleUnit:'',
                },

                currentState:1,

                rules: {
                    ruletype: [{ required: true, message: '请选择规则类型', trigger: 'change' }],
                    ruleno: [{ required: false, message: '请输入规则编码', trigger: 'change' }],
                    rulename: [{ required: true, message: '请选择规则名称', trigger: 'change' }],
                    rulecontent: [{ required: true, message: '请输入规则内容', trigger: 'change' }],
                    status: [{ required: true, message: '请选择状态', trigger: 'change' }],
                    remark: [{ required: false, message: '请选择状态', trigger: 'change' }],
                    ruleUnit: [{ required: true, message: '请选择单位', trigger: 'change' }],
                },

                rowId:0,
                ruleTypeList:[],
                ruleTypeMap:[],

                ruleNameList:[],
                ruleNameMap:[],


                processList:[],
                processMap:[],

                ruleUnitList:[],
                ruleUnitMap:[],


                title:'',//存表名
                EnhanceJS:'',
                cgButtonList:[],
                groupTag:[],
                queryInfo: [],
                code: '',
                // 表头
                columns: [
                ],
                //列设置
                settingColumns:[],
                //列定义
                defColumns: [
                    {
                        title: "序号",
                        dataIndex: '',
                        key:'rowIndex',
                        width:60,
                        align: 'center',
                        customRender:function (t,r,index) {
                            return parseInt(index)+1;
                        }
                    },
                    {
                        title: '规则编码',
                        align: 'center',
                        dataIndex: 'ruleno',
                        scopedSlots: { customRender: "ruleno" },
                    },
                    {
                        title: '规则名称',
                        align: 'center',
                        dataIndex: 'rulename',
                        scopedSlots: { customRender: 'rulename' }
                    },
                    {
                        title: '规则类型',
                        align: 'center',
                        dataIndex: 'ruletype',
                        scopedSlots: { customRender: 'ruletype' }
                    },
                    {
                        title: '规则内容',
                        align: 'center',
                        dataIndex: 'rulecontent',
                        customRender: (text,record) => {
                            if (!record.rulecontent) {
                                return "";
                            } else {
                                let result = '';
                                if(record.rulename=='1'){
                                    let arrayList = record.rulecontent.split(',');
                                    arrayList.forEach(item=>{
                                        result = result+this.processMap[item].title+',';
                                    })
                                    if(arrayList.length>0){
                                        result = result.substring(0,result.length-1);
                                    }
                                }else{
                                    result = record.rulecontent;

                                     if(record.ruleUnit!=-1){
                                         result = result+ this.ruleUnitMap[record.ruleUnit].title;
                                     }
                                }


                                return  result;
                            }
                        },
                    },
                    {
                        title: '创建人',
                        align: 'center',
                        dataIndex: 'createBy',
                    },
                    {
                        title: '创建日期',
                        align: 'center',
                        dataIndex: 'createTime',
                    },
                    {
                        title: '更新人',
                        align: 'center',
                        dataIndex: 'updateBy',
                    },
                    {
                        title: '更新日期',
                        align: 'center',
                        dataIndex: 'updateTime',
                    },
                    {
                        title: '状态',
                        align: 'center',
                        dataIndex: 'status_dictText',
                        scopedSlots: { customRender: 'status_dictText' }
                    },
                    {
                        title: '备注',
                        align: 'center',
                        width:240,
                        dataIndex: 'remark',
                    },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        align: 'center',
                        scopedSlots: { customRender: 'action' }
                    }
                ],
                url: {
                    list: '/mes-quality/mesQcInspectRule/list',
                    delete: '/mes-quality/mesQcInspectRule/delete',
                    deleteBatch: '/mes-quality/mesQcInspectRule/deleteBatch',
                    exportXlsUrl: '/mes-quality/mesQcInspectRule/exportXls',
                    importExcelUrl: '/mes-quality/mesQcInspectRule/importExcel',
                    getColumns: '/mes-quality/online/cgform/api/getColumns/',
                    buttonAction: '/mes-quality/online/cgform/api/doButton',
                },
                dictOptions:{},
            }
        },
        computed: {
            importExcelUrl: function(){
                return `${api.test}${this.url.importExcelUrl}`;
            },
            getWidth:function(){
                if(this.defColumns.length > 14){
                    return {width : '500px'}
                }
            },
            tableScroll:function(){
                if(this.columns.length > 13){
                    return { x: this.columns.length*150-450 }
                }
            }
        },
        created() {
            this.initRuleUnitList();
            this.initProcessType();
            this.initRuleNameList();
            this.initRuleNo();
            this.initRuleTypeList();
            this.initButtonList();
            this.initColumns();
        },

        methods: {

            clickThenSelect(record) {
                return {
                    on: {
                        click: () => {
                            if(record.id){
                                this.rowId = record.id;
                                //this.onSelectChange(record.id.split(","), [record]);
                            }

                        },
                    },
                };
            },
            setRowClassName(record){
                return record.id === this.rowId ? 'clickRowStyl' : '';
            },


            rulenameSelectChange(){
                if(this.form.rulename==1){
                    this.showContentSelect = true;
                    this.form.rulecontent = [];
                    this.contentNum = false;
                    this.form.ruleUnit='';
                }else{
                    this.showContentSelect = false;
                    this.form.rulecontent = '';
                }
            },

            ruleUnitSelectChange(){

                if(this.form.ruleUnit==-1){
                    this.contentNum = false;
                    this.form.rulecontent = '';
                }else{
                    this.contentNum = true;
                    this.form.rulecontent = 0;
                }

            },


            //封装listToMap
            listToMap(list,name){
                let map = {};
                for(let i in list){
                    map[list[i][name]] = list[i];
                }
                return map;
            },

            initRuleNo(){
              getAction('/basic-business/sys/fillRule/getFillRule/',{ruleCode:'mes_ruleno_rule'}).then(res=>{
                  if(res.success){
                      this.ruleNo = res.data;
                  }
              })
            },

            initRuleTypeList(){
                getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_ruletype'}).then(res=>{
                    if(res.success){
                        this.ruleTypeList = res.data;
                        this.ruleTypeMap = this.listToMap(this.ruleTypeList,'value');
                    }
                })
            },

            initRuleNameList(){
                getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_otherrule_rulename'}).then(res=>{
                    if(res.success){
                        this.ruleNameList = res.data;
                        this.ruleNameMap = this.listToMap(this.ruleNameList,'value');
                    }
                })
            },

            initProcessType(){
                getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_process_type'}).then(res=>{
                    if(res.success){
                        this.processList = res.data;
                        this.processMap = this.listToMap(this.processList,'value');
                    }
                })
            },

            initRuleUnitList(){
                getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_otherrule_ruleunit'}).then(res=>{
                    if(res.success){
                        this.ruleUnitList = res.data;
                        this.ruleUnitMap = this.listToMap(this.ruleUnitList,'value')
                    }
                })
            },


            openAddBtn(){
                this.pModalVisible = true;
                this.pTitle = '新增';
                this.currentState=1;
                this.initopenAddBtnData();
                this.form.ruleno = this.ruleNo;

            },
            initopenAddBtnData(){
                this.form={
                    ruletype:'',
                    ruleno:'',
                    rulename:'',
                    rulecontent:[],
                    status:1,
                    remark:'',
                    ruleUnit:'',
                };
            },

            openEditBtn(record){
                this.pModalVisible = true;
                this.pTitle = '编辑';
                this.currentState=2;
                this.editP = record;
                this.form={
                    ruletype:record.ruletype+'',
                    ruleno:record.ruleno,
                    rulename:record.rulename,
                    status:parseInt(record.status),
                    remark:record.remark,
                    ruleUnit:record.ruleUnit+'',
                };


                if(record.rulename=='1'){
                    this.showContentSelect = true;
                    let array = [];
                    if(record.rulecontent){
                        let dataArray = record.rulecontent.split(',');
                        dataArray.forEach(item=>{
                            array.push(item);
                        })
                    }

                   // this.form.rulecontent = array;
                    Vue.set(this.form,'rulecontent', array)
                }else{
                    this.showContentSelect = false;

                    Vue.set(this.form,'rulecontent', record.rulecontent)
                   // this.form.rulecontent = record.rulecontent
                }

                if(this.form.ruleUnit==-1){
                    this.contentNum = false;
                }else{
                    this.contentNum = true;
                }

            },


            pModalOk(){
                this.$refs.ruleForm.validate(valid => {
                    if (valid) {
                        if(this.currentState==1){
                            this.addPOperation();
                        }else{
                            this.editPOperation();
                        }
                    }else{
                        return false;
                    }
                });
            },

            initFormData(){
              this.form={
                    ruletype:'',
                        ruleno:'',
                        rulename:'',
                        rulecontent:'',
                        status:'',
                        remark:'',
                        ruleUnit:'',
                };
            },

            formDataReset(){
                let data = this.form;
                let rulecontent = '';
                if(data.rulename==1){
                    data.ruleUnit = '';
                    data.rulecontent.forEach(item=>{
                        rulecontent = rulecontent+item+',';
                    })

                    if(data.rulecontent.length>0){
                        rulecontent = rulecontent.substring(0,rulecontent.length-1);
                    }

                }else{
                    rulecontent = data.rulecontent;
                }

                let d = {
                    ruletype:data.ruletype,
                    ruleno:data.ruleno,
                    rulename:data.rulename,
                    rulecontent:rulecontent,
                    ruleUnit:data.ruleUnit,
                    status:data.status,
                    remark:data.remark
                }

                return d;
            },


            addPOperation(){
                let data = this.formDataReset();
                postAction('/mes-quality/mesQcInspectRule/add',data).then(res=>{
                    if(res.success){
                        this.$message.success("新增成功!");
                        this.pModalVisible  = false;
                        this.initRuleNo();
                        this.initFormData();
                        this.loadData();
                    }else{

                        this.$message.warning(res.msg)
                    }
                })
            },


            editPOperation(){
                let data = this.formDataReset();
                let p = this.editP;
                p.ruletype=data.ruletype;
                p.ruleno=data.ruleno;
                p.rulename=data.rulename;
                p.rulecontent=data.rulecontent;
                p.ruleUnit=data.ruleUnit;
                p.status=data.status;
                p.remark=data.remark;

                putAction('/mes-quality/mesQcInspectRule/edit',p).then(res=>{
                    if(res.success){
                        this.$message.success("修改成功!");
                        this.pModalVisible  = false;
                        this.initFormData();
                        this.loadData();
                    }else{
                        this.$message.warning(res.msg)
                        this.loadData();
                    }
                })

            },


            deleteBtn(id){
                deleteAction('/mes-quality/mesQcInspectRule/delete/'+id).then(res=>{
                    if(res.success){
                        this.loadData();
                        this.$message.success("删除成功!")
                    }else{
                        this.$message.warning("删除失败!")
                    }
                })
            },




            initColumns(){
                //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
                //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

                var key = this.$route.name+":colsettings";
                let colSettings= Vue.ls.get(key);
                if(colSettings==null||colSettings==undefined){
                    let allSettingColumns = [];
                    this.defColumns.forEach(function (item,i,array ) {
                        allSettingColumns.push(item.dataIndex);
                    })
                    this.settingColumns = allSettingColumns;
                    this.columns = this.defColumns;
                }else{
                    this.settingColumns = colSettings;
                    const cols = this.defColumns.filter(item => {
                        if(item.key =='rowIndex'|| item.dataIndex=='action'){
                            return true;
                        }
                        if (colSettings.includes(item.dataIndex)) {
                            return true;
                        }
                        return false;
                    })
                    this.columns =  cols;
                }
            },
            //列设置更改事件
            onColSettingsChange (checkedValues) {
                var key = this.$route.name+":colsettings";
                Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
                this.settingColumns = checkedValues;
                const cols = this.defColumns.filter(item => {
                    if(item.key =='rowIndex'|| item.dataIndex=='action'){
                        return true
                    }
                    if (this.settingColumns.includes(item.dataIndex)) {
                        return true
                    }
                    return false
                })
                this.columns =  cols;
            },

            //高级查询方法
            handleSuperQuery(arg) {
                if(!arg){
                    this.superQueryParams=''
                    this.superQueryFlag = false
                }else{
                    this.superQueryFlag = true
                    this.superQueryParams=JSON.stringify(arg)
                }
                this.loadData()
            },
            // 获取查询条件
            getQueryParams() {
                let sqp = {}
                if(this.superQueryParams){
                    sqp['superQueryParams']=encodeURI(this.superQueryParams)
                }
                var param = Object.assign(sqp, this.queryParam, this.isorter);
                param.field = this.getQueryField();
                param.pageNo = this.ipagination.current;
                param.limit = this.ipagination.pageSize;
                return filterObj(param);
            },
            initDictConfig(){
            },

            // 弹出窗组件
            showDemoModal() {
                this.$refs.modalCompon.modalShow();
            },
            // 点击btn获取数据
            btnGetData(tableName,title){
                getAction(`${this.url.getColumns}`,{
                    tableName:tableName
                }).then(
                    res=>{
                        if(res.code == 0){
                            this.queryInfo = res.data.columns
                            this.title = title
                            this.dictOptions = res.data.dictOptions
                            this.showDemoModal()
                        }else{
                            this.$message.warning(res.msg);
                        }
                    }
                )
            },

            //筛选分组
            getGroupTag(arrList) {
                let arr = [];
                var map = {},
                    dest = [];
                arrList.forEach((item, index) => {
                    if (item.groupTag) {
                        arr.push(item);
                    }
                });
                for (var i = 0; i < arr.length; i++) {
                    var ai = arr[i];
                    if (!map[ai.groupTag]) {
                        dest.push({
                            groupTag: ai.groupTag,
                            name: ai.groupName,
                            data: [ai]
                        });
                        map[ai.groupTag] = ai;
                    } else {
                        for (var j = 0; j < dest.length; j++) {
                            var dj = dest[j];
                            if (dj.groupTag == ai.groupTag) {
                                dj.data.push(ai);
                                break;
                            }
                        }
                    }
                }
                this.groupTag = dest
                console.log(dest);
            },
            showLinkButton(item,record){
                let btn = new ButtonExpHandler(item.exp,record);
                return btn.show;
            },
            initButtonList(){
                getAction(`${this.url.getColumns}2bf833cc1b014914a95c5f42c759bb18`).then((res)=>{
                    console.log("--获取自定义按钮->>",res);
                    if(res.success){
                        this.code = res.data.code;
                        this.initCgButtonList(res.data.cgButtonList);
                        this.initCgEnhanceJs(res.data.enhanceJs);
                        this.getGroupTag(res.data.cgButtonList);
                    }else{
                        this.$message.warning(res.msg)
                    }
                })
            },
            initCgEnhanceJs(enhanceJs){
                //console.log("--onlineList-js增强",enhanceJs)
                if(enhanceJs){
                    let Obj = eval ("(" + enhanceJs + ")");
                    this.EnhanceJS = new Obj(getAction,postAction,deleteAction);
                    this.cgButtonJsHandler('created')
                }else{
                    this.EnhanceJS = ''
                }
            },
            initCgButtonList(btnList){
                let linkArr = []
                let buttonArr = []
                if(btnList && btnList.length>0){
                    for(let i=0;i<btnList.length;i++){
                        let temp = btnList[i]
                        if(temp.buttonStyle=='button'){
                            buttonArr.push(temp)
                        }else if(temp.buttonStyle=='link'){
                            linkArr.push(temp)
                        }
                    }
                }
                this.cgButtonLinkList = [...linkArr]
                this.cgButtonList=[...buttonArr]
                console.log("链接增强", this.cgButtonLinkList);
            },
            cgButtonJsHandler(buttonCode){
                if(this.EnhanceJS[buttonCode]){
                    this.EnhanceJS[buttonCode](this)
                }
            },
            cgButtonActionHandler(buttonCode){
                //处理自定义button的 需要配置该button自定义sql
                if(!this.selectedRowKeys || this.selectedRowKeys.length==0){
                    this.$message.warning("请先选中一条记录")
                    return false
                }
                if(this.selectedRowKeys.length>1){
                    this.$message.warning("请只选中一条记录")
                    return false
                }
                let params = {
                    formId:this.code,
                    buttonCode:buttonCode,
                    dataId:this.selectedRowKeys[0]
                }
                console.log("自定义按钮请求后台参数：",params)
                postAction(this.url.buttonAction,params).then(res=>{
                    if(res.success){
                        this.loadData()
                        this.$message.success("处理完成!")
                    }else{
                        this.$message.warning("处理失败!")
                    }
                })

            },
            cgButtonLinkHandler(record,buttonCode,optType){
                if(optType=="js"){
                    if(this.EnhanceJS[buttonCode]){
                        this.EnhanceJS[buttonCode](this,record)
                    }
                }else if(optType=="action"){
                    let params = {
                        formId:this.code,
                        buttonCode:buttonCode,
                        dataId:record.id
                    }
                    console.log("自定义按钮link请求后台参数：",params)
                    postAction(this.url.buttonAction,params).then(res=>{
                        if(res.success){
                            this.loadData()
                            this.$message.success("处理完成!")
                        }else{
                            this.$message.warning("处理失败!")
                        }
                    })
                }
            },
        }
    }
</script>
<style scoped>
    @import '~@assets/less/common.less';
    /deep/.clickRowStyl td{
        background:#00b4ed !important;
    }

    /deep/.ant-table-tbody.clickRowStyl:hover>td {
        background-color:#00b4ed
    }
</style>
